package com.oracle.application.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class MQConfig {

    @Bean
    public Queue orderDlxQueue(){
        return new Queue("orderDlxQueue");
    }
    @Bean
    public DirectExchange dlxExchange(){
        return new DirectExchange("dlxExchange");
    }
    @Bean
    public Binding dlxOrderQueueAndDirectExchange(){
        Binding with = BindingBuilder.bind(orderDlxQueue()).to(dlxExchange()).with("#");
        return with;
    }
    @Bean
    public Queue orderCreateQueue(){

        Map<String,Object> mapProps=new HashMap<>();
        mapProps.put("x-message-ttl",1000*6*3);
        mapProps.put("x-dead-letter-exchange","dlxExchange");
        mapProps.put("x-dead-letter-routing-key","#");

        return new Queue("orderCreateQueue",false,false,false,mapProps);
    }

    @Bean
    public DirectExchange orderDirectExchange(){
        return new DirectExchange("orderDirectExchange");
    }

    @Bean
    public Binding orderQueueAndDirectExchange(){
        return BindingBuilder.bind(orderCreateQueue()).to(orderDirectExchange()).with("order.create");
    }

}
